<?php
class SukiensController extends AppController {
    public $helpers = array('Html', 'Form');
    public function index() {
        $this->set('sukiens', $this->Sukien->find('all')); 
    }
    public function add()
    {
    	if(!empty($this->data))
    	{
          /*  		$this->Sukien->create();*/

//$this->layout = 'ajax';
          if ($this->request->is('sukien')) {
//debug($this->request->data);die();
            $this->Sukien->create();
            if (is_uploaded_file($this->request->data['Sukien']['anhnho']['tmp_name'])){

                mkdir('img/image'. DS . 'anhnho' . DS . $this->request->data['Sukien']['username'], 0777, true);
                move_uploaded_file(
                    $this->request->data['Sukien']['anhnho']['tmp_name'],
                    "img/image". DS . 'anhnho' . DS . $this->request->data['Sukien']['username'] . DS . $this->request->data['Sukien']['anhnho']['name']
                    );
                $this->request->data['Sukien']['anhnho'] = $this->request->data['Sukien']['anhnho']['name'];
            }
        }
    if($this->Sukien->save($this->request->data))
    {
     $this->Session->setFlash("Đã Lưu Được Dữ Liệu");
     $this->redirect(array('action'=>'index'),null,true);
 }
    else
     $this->Session->setFlash("Không Lưu Được Dữ Liệu");
}
}
public function view($id){
  $this->set('sukien', $this->Sukien->findById($id));
}
public function edit($id){
    $this->Sukien->id=$id;
    if(empty($this->data))
    {
    $this->data=$this->Sukien->read();
     }
     else
       if($this->Sukien->save($this->data))
       {
        $this->Session->setFlash('Đã Sửa Sự Kiện Thành Công.');
        $this->redirect(array('action'=>'index'));
       }
    }

public function delete($id) {
    $this->Sukien->delete($id);
    $this->Session->setFlash('Đã xóa Được Dữ Liệu: '.$id.' công việc đã xong.');
    $this->redirect(array('action'=>'index'));
}

}
?>